<?php

class Core_Model_Foundation_Collection_Road extends Dcmp_Model_Collection_Strong {

    public function __construct() {
        parent::__construct();
        $this->setItemClass('foundation/road');
        $this->from('{t}foundation_road', 'a');
    }

    public function sortBy($name, $dir) {
        $dir == 'asc' ? $this->asc("a.$name") : $this->desc("a.$name");
        return parent::sortBy($name, $dir);
    }

    public function filterBy($name, $arg) {
        switch ($name) {
            case 'id':
                return $this->eq('a.id', ':id:i')->addParameter('id', $arg);
            case 'provincename':
                return $this->like('a.province_name', ':provinceName:s')->addParameter('provinceName', "%$arg%");
            case 'cityname':
                return $this->like('a.city_name', ':cityName:s')->addParameter('cityName', "%$arg%");
            case 'townstreetname':
                return $this->like('a.townstreet_name', ':townstreetName:s')->addParameter('townstreetName', "%$arg%");
            case 'roadname':
                return $this->like('a.road_name', ':roadName:s')->addParameter('roadName', "%$arg%");
            case 'districtname':
                return $this->like('a.district_name', ':districtName:s')->addParameter('districtName', "%$arg%");
            case 'ids':
                return $this->contain('a.id', ':ids:s')->addParameter('ids', $arg);
        }
        return parent::filterBy($name, $arg);
    }

}